package com.mixsmart.core.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mixsmart.core.bean.Paginate;
import com.mixsmart.core.bean.entity.IEntityBean;
import com.mixsmart.core.bean.entity.NullEntityBean;
import com.mixsmart.core.dao.IQueryEntityDao;
import com.mixsmart.core.service.IQueryService;
import com.mixsmart.spellsql.ICondition;

/**
 * 查询服务--实现类
 * @author lmq
 * @version 1.0
 * @since JDK版本大于等于1.6
 * 2016年1月15日
 */
@Service
public class QueryService implements IQueryService {

	@Autowired
	private IQueryEntityDao<NullEntityBean, String> queryDao;
	
	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> E find(Class<? extends IEntityBean> clazz, ICondition condition) {
		return this.queryDao.findUnique(clazz, condition);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> List<E> finds(Class<? extends IEntityBean> clazz, ICondition condition) {
		return this.queryDao.finds(clazz, condition);
		
	}
	
	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public List<Object> queryObjSql(String sql, HashMap<String, Object> params) {
		return queryDao.queryObjSql(sql, params);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public List<Object> queryObjSqlFilter(String sql, HashMap<String, Object> params) {
		return queryDao.queryObjSqlFilter(sql, params);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public List<Object> queryObjHql(String hql, HashMap<String, Object> params) {
		return queryDao.queryObjHql(hql, params);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public List<Object> queryObjHqlFilter(String hql, HashMap<String, Object> params) {
		return queryDao.queryObjHqlFilter(hql, params);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> List<E> querySql(String sql, HashMap<String, Object> params, Class<?> clazz) {
		return queryDao.querySql(sql, params, clazz);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> List<E> querySqlFilter(String sql, HashMap<String, Object> params, Class<?> clazz) {
		return queryDao.querySqlFilter(sql, params, clazz);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public Paginate<Object> queryObjSql(String sql, HashMap<String, Object> params, int pageNo, int pageSize) {
		return queryDao.queryObjSql(sql, params, pageNo, pageSize);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public Paginate<Object> queryObjSqlFilter(String sql, HashMap<String, Object> params, int pageNo, int pageSize) {
		return queryDao.queryObjSqlFilter(sql, params, pageNo, pageSize);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> Paginate<E> querySql(String sql, HashMap<String, Object> params, int pageNo, int pageSize, Class<?> clazz) {
		return queryDao.querySql(sql, params, pageNo, pageSize, clazz);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public <E> Paginate<E> querySqlFilter(String sql, HashMap<String, Object> params, int pageNo, int pageSize, Class<?> clazz) {
		return queryDao.querySql(sql, params, pageNo, pageSize, clazz);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public long countSql(String sql, HashMap<String, Object> params) {
		return queryDao.countSql(sql, params);
	}

	@Override
	@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
	public long countSqlFilter(String sql, HashMap<String, Object> params) {
		return queryDao.countSqlFilter(sql, params);
	}
	
}
